﻿<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <meta name="renderer" content="webkit|ie-comp|ie-stand">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta http-equiv="Cache-Control" content="no-siteapp"/>
    <title>添加交接单</title>

    <link th:href="@{/erp/assets/css/bootstrap.min.css}" rel="stylesheet"/>
    <link rel="stylesheet" th:href="@{/erp/css/style.css}"/>
    <link th:href="@{/erp/assets/css/codemirror.css}" rel="stylesheet">
    <link rel="stylesheet" th:href="@{/erp/assets/css/ace.min.css}"/>
    <link rel="stylesheet" th:href="@{/erp/assets/css/font-awesome.min.css}"/>
    <script th:src="@{/erp/js/jquery-1.9.1.min.js}"></script>
    <script th:src="@{/erp/assets/js/bootstrap.min.js}"></script>
    <script type="text/javascript" th:src="@{/erp/Widget/Validform/5.3.2/Validform.min.js}"></script>
    <script th:src="@{/erp/assets/js/jquery.dataTables.min.js}"></script>
    <script th:src="@{/erp/assets/js/jquery.dataTables.bootstrap.js}"></script>
    <script th:src="@{/erp/assets/js/typeahead-bs2.min.js}"></script>
    <script th:src="@{/erp/assets/layer/layer.js}" type="text/javascript"></script>
    <script th:src="@{/erp/assets/js/jquery-ui-1.10.3.custom.min.js}"></script>
    <script th:src="@{/erp/assets/js/jquery.ui.touch-punch.min.js}"></script>
    <script th:src="@{/erp/assets/js/ace-elements.min.js}"></script>
    <script th:src="@{/erp/assets/js/ace.min.js}"></script>
    <script th:src="@{/erp/js/lrtk.js}" type="text/javascript"></script>
    <script th:src="@{/erp/assets/laydate/laydate.js}" type="text/javascript"></script>

</head>
<body>
<form>
    <div class="add_menber" id="add_menber_style">
        <ul class=" page-content">
            <li>
                <label class="label_name">订单编号：</label>
                <span class="add_name">
                       <input value="" name="orderNo" type="text"  class="text_add"/>
                </span>
                <div class="prompt r_f"></div>
            </li>
            <li>
                <label class="label_name">收货仓库：</label>
                <span class="add_name">
                        <select name='warehouseId' style='width:200px'>
                            <option value='' selected>请选择</option>
                            <option th:each="x : ${warehouseList}" th:value="${x.id}" th:text="${x.warehouseName}"></option>
                        </select>
                    </span>
                <div class="prompt r_f"></div>
            </li>
            <li>
                <label class="label_name">生产部门：</label>
                <span class="add_name">
                        <select name='deptId' style='width:200px'>
                            <option value='' selected>请选择</option>
                            <option th:each="x : ${deptList}" th:value="${x.id}" th:text="${x.deptName}"></option>
                        </select>
                    </span>
                <div class="prompt r_f"></div>
            </li>
            <div class="prompt r_f"></div>
            <li><label class="label_name">入库数量：</label>
                <span class="add_name"><input name="num" type="text" class="text_add"/></span>
                <div class="prompt r_f"></div>
            </li>
            <li><label class="label_name">交接人：</label>
                <span class="add_name"><input name="peo" type="text" class="text_add" placeholder="请至输入交接人"/></span>
                <div class="prompt r_f"></div>
            </li>
            <li><label class="label_name">备注：</label>
                <span class="add_name"><input name="remark" type="text" class="text_add"/></span>
                <div class="prompt r_f"></div>
            </li>
        </ul>
    </div>
    <br>
    <div class="" style=" text-align:center">
        <input class="btn btn-primary" id="btn_sure" type="button" value="确认">
        <input class="btn btn-primary" id="btn_qx" type="reset" value="取消">
    </div>
</form>



<script>

    //正整数验证
    function isPInt(str) {
        var g = /^[1-9]*[1-9][0-9]*$/;
        return g.test(str);
    }

    //正整数验证
    function isName(str) {
        var g = /^[\u4e00-\u9fa5]{2,6}$/;
        return g.test(str);
    }

    /*检查订单号是否存在*/
    function checkOrderNo(ids) {
        var res = false;
        $.ajax({
            url: '/handover/checkOrderNo',
            contentType: "application/x-www-form-urlencoded; charset=utf-8",
            async:false,
            type: 'post',
            dataType: 'json',
            data: {orderNo:ids},
            success: function (e) {
                res = e.rs;
            }
        })
        return res;
    }

    jQuery(function ($) {
        $('#btn_sure').on('click', function () {
            var ids = $("input[name='orderNo']").val();
            var wareNames = $("select[name='warehouseId']").val();
            var nums = $("input[name='num']").val();
            var heads = $("input[name='peo']").val();
            if (ids == "") {
                layer.msg('请选择订单编号!', {icon: 5, time: 2000});
                return;
            } else if (checkOrderNo(ids)) {
                layer.msg('该订单号已存在!', {icon: 5, time: 2000});
                return;
            } else if(wareNames == "") {
                layer.msg('请选择收货仓库!', {icon: 5, time: 2000});
                return;
            }else if(!isPInt(nums)) {
                layer.msg('请输入数字,入库数量必须为大于0!', {icon: 5, time: 2000});
                return;
            }else  if(heads== null || heads == '') {
                layer.msg('交接人不能为空!', {icon: 5, time: 2000});
                return;
            }else {
                $.ajax({
                    url: '/handover/add',
                    contentType: "application/x-www-form-urlencoded; charset=utf-8",
                    type: 'post',
                    dataType: 'json',
                    data: $('form').serialize(),
                    success: function (e) {
                        if (e.rs) {
                            layer.msg('添加成功!',{
                                icon: 1,
                                time:800,
                                end: function () {
                                    parent.location.reload();
                                    //关闭弹出窗
                                    var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
                                    parent.layer.close(index);//关闭弹出层
                                }
                            });

                        }else {
                            layer.msg('添加失败!',{
                                icon: 2,
                                time:2000,
                                end: function () {
                                    parent.location.reload();
                                    //关闭弹出窗
                                    var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
                                    parent.layer.close(index);//关闭弹出层
                                }
                            });
                        }
                    }
                })
            }

        });

        $("#btn_qx").on("click",function () {
            var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
            parent.layer.close(index);//关闭弹出层
            window.location.href="/production/handover/cp_jjdPage";
        });

    })



</script>

</body>
</html>

